package fpsf
{
	import flash.display.DisplayObject;
	import mx.core.UIComponent;
	import mx.events.ModuleEvent;
	import mx.modules.IModuleInfo;
	import mx.modules.ModuleManager;
	
	public class ModuleLoader
	{
		private var imodule:IModuleInfo;
		private var moduledisplay:DisplayObject;
		private var addTo:UIComponent;
		
		public function ModuleLoader(url:String,addTo:UIComponent,runAfter:Function)
		{
			this.addTo = addTo;
			
			imodule = ModuleManager.getModule(url);
			imodule.addEventListener(ModuleEvent.READY,function():void {runAfter();} ,false);
			imodule.load();
		}
		
		public function createModule():void
		{
			moduledisplay = addTo.addChild(imodule.factory.create() as DisplayObject);
		}
		
		public function removeModule():void
		{
			imodule.unload();
			addTo.removeChild(moduledisplay);
		}
		
	}
}